﻿
$(function() {
    if (jQuery.url.param("ID") != undefined) {
        EmployeeId = jQuery.url.param("ID");
    }
    JSUtility.url = '../Handler/AjaxHandle.ashx';
    JSUtility.param = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.EmployeeTrainingMappingPresenter", Method: "Search", Options: {} };
    top.autoResize({ dataGrid: '#Grid', callback: InitPersonaTraininglist, par: {}, method: 'Search' });
    $('#btnSubmit,#btnCancel').linkbutton();

    JSUtility.window_edit = $("#TrainingWin");
    $("#TrainingWin").window({ top: 43 });
    //绑定添加在职培训信息
    $("#btnAdd").bind("click", function() {
        InitAllTraininglist();
        JSUtility.add();
    });
    //结束


    $("#btnDel").click(function() {
        var ids = [];
        var rows = $('#Grid').datagrid('getSelections');
        if (rows.length > 0) {
            for (var i = 0; i < rows.length; i++) {
                ids.push(rows[i].Id);
            }
            $.messager.confirm("删除提示", "是否确认要删除该条信息?", function(b) {
                var p = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.EmployeeTrainingMappingPresenter", Method: "DeletePersonalTrain", Options: {} };
                p.Options["id"] = ids.join(';');
                p.Options["EmployeeId"] = EmployeeId;
                $.ajax({
                    type: "post",
                    url: JSUtility.url,
                    data: $.toJSON(p),
                    dataType: "json",
                    success: function(data) {
                        if (data.flag) {
                            location.reload();
                            $.messager.show({ msg: data.msg, title: "info" });
                        } else {
                            $.messager.alert('错误', data.msg, 'error');
                        }
                    }
                });
            });
        }
        else {
            $.messager.alert('错误', "请选择要删除的在职教育信息!", 'info');
        }
    });

    $("#btnSubmit").click(function() {
        var ids = []; //在职培训信息的Id
        var rows = $('#AllGrid').datagrid('getSelections');
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].Id);
        }
        if (ids.length > 0) {
            var p = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.EmployeeTrainingMappingPresenter", Method: "AddPersonalTrain", Options: {} };
            p.Options["id"] = ids.join(';');
            p.Options["EmployeeId"] = EmployeeId;
            $.ajax({
                type: "post",
                url: JSUtility.url,
                data: $.toJSON(p),
                dataType: "json",
                success: function(data) {
                    if (data.flag) {
                        $("#AllGrid").datagrid('clearSelections');
                        JSUtility.close();
                        $("#Grid").datagrid('reload');
                        $.messager.show({ msg: data.msg, title: "info" });
                    } else {
                        $.messager.alert('错误', data.msg, 'error');
                    }
                }
            });
        } else {
            $.messager.alert('系统提示', '选择要参训的在职教育项目!', 'info');
        }
    });

    $('#btnCancel').click(JSUtility.close);
});
//加载登陆人的参加的在职培训信息
function InitPersonaTraininglist(op, method, size) {
    JSUtility.param.Options["EmployeeId"] = EmployeeId;
    var p = JSUtility.param;
    JSUtility.grid = $('#Grid').datagrid({
        width: size.width,
        height: size.height-20,
        pageSize: 20,
//        pageList: [Math.round(size.height / 25)],
        striped: true,
        queryParams: { "json": $.toJSON(p) },
        url: JSUtility.url,
        frozenColumns: [[{ field: 'ck', checkbox: true}]]
    });
}

var EmployeeId;
//加载所有的在职在职培训信息
function InitAllTraininglist() {
    var p = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.TrainingPresenter", Method: "Paged", Options: {} };
    JSUtility.grid = $('#AllGrid').datagrid({
        width: 700,
        height: 400,
        pageSize: 10,
        striped: true,
        queryParams: { "json": $.toJSON(p) },
        url: JSUtility.url,
        frozenColumns: [[{ field: 'ck', checkbox: true}]]
    });
}
